package com.gzit.common;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;

import com.gzit.R;
import com.gzit.utils.AndroidUtils;

/**
 * @author wuzhansheng
 * 
 * @param <Params>
 * @param <Progress>
 * @param <Result>
 */
public abstract class ModelAsyncTask<Params, Progress, Result> extends
		AsyncTask<Params, Progress, Result> {

	protected Activity bindActivity;
	protected ProgressDialog dialog;
	protected String loadingMessageContent;

	public ModelAsyncTask(Activity activity, String msg) {

		this.bindActivity = activity;
		this.loadingMessageContent = msg;
	}

	public ModelAsyncTask(Activity activity) {

		this(activity, AndroidUtils.getResourceString(activity,
				R.string.gzit_loading_dialog_content));
	}

	protected void prepareProgressDialog() {
		dialog = ProgressDialog.show(bindActivity, "", loadingMessageContent);
		dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		dialog.show();

	}

	protected void dismissProgressDialog() {
		dialog.dismiss();
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		prepareProgressDialog();

	}

	protected void onPostExecute(Result result) {

		dismissProgressDialog();
	};

}
